package org.dtrd.config.wechat.config;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.*;

/**
 * 微信常量
 *
 * @author qr
 * @date 2022/3/19 10:28
 */
public final class WechatConstant {

    @Getter
    @AllArgsConstructor
    public enum OfficialAccountTag {
        /**
         * 客户标签id
         */
        USER_TAG_ID(101),

        /**
         * 医生标签id
         */
        DOCTOR_TAG_ID(100),
        /**
         * 医助、顾问标签id
         */
        CONSULTANT_TAG_ID(102);

        private int tag;

        public static boolean isUserTag(Integer tagId) {
            return Objects.equals(tagId, USER_TAG_ID.tag);
        }

        public static boolean isDoctorTag(Integer tagId) {
            return Objects.equals(tagId, DOCTOR_TAG_ID.tag);
        }

        public static boolean isConsultantTag(Integer tagId) {
            return Objects.equals(tagId, CONSULTANT_TAG_ID.tag);
        }

        public static boolean isValidTag(Integer tagId) {
            if (tagId == null) {
                return false;
            }
            Optional<OfficialAccountTag> any = Arrays.stream(values()).filter(tag -> tag.tag == tagId).findAny();
            return any.isPresent();
        }

        public static List<Integer> getMutexTagIdList(Integer tagId) {
            List<Integer> list = new ArrayList<>(2);
            if (tagId == USER_TAG_ID.tag) {
                list.add(DOCTOR_TAG_ID.tag);
                list.add(CONSULTANT_TAG_ID.tag);
            } else if (tagId == DOCTOR_TAG_ID.tag) {
                list.add(USER_TAG_ID.tag);
                list.add(CONSULTANT_TAG_ID.tag);
            } else if (tagId == CONSULTANT_TAG_ID.tag) {
                list.add(DOCTOR_TAG_ID.tag);
                list.add(USER_TAG_ID.tag);
            }
            return list;
        }

    }

    public final static Integer WECHAT_SUCCESS_CODE = 0;


    /**
     * 创建微信二维码的类型
     */
    @AllArgsConstructor
    @Getter
    public enum QrCodeType {
        /**
         * 临时的整型参数值
         */
        QR_SCENE,
        /**
         * 临时的字符串参数值
         */
        QR_STR_SCENE,
        /**
         * 永久的整型参数值
         */
        QR_LIMIT_SCENE,
        /**
         * 永久的字符串参数值
         */
        QR_LIMIT_STR_SCENE;

    }

    @AllArgsConstructor
    @Getter
    public enum MsgType {
        text,
        image,
        voice,
        video,
        music,
        news;
    }

    /**
     * 客户端版本
     */
    @AllArgsConstructor
    @Getter
    public enum ClientPlatformType {
        IOS(1),
        Android(2),
        Others(3);

        int type;

        public static ClientPlatformType valueOf(Integer type) {
            return Arrays.stream(values()).filter(c -> Objects.equals(c.getType(), type)).findAny().orElse(null);
        }
    }

    /**
     * 小程序版本
     */
    @Getter
    @AllArgsConstructor
    public enum MiniprogramVersion {
        /**
         * 正式版
         */
        release("release"),
        /**
         * 试用版
         */
        trial("trial"),
        /**
         * 开发版
         */
        develop("develop");

        private final String version;

    }

    /**
     * 小程序诶性
     */
    @Getter
    @AllArgsConstructor
    public enum WechatMiniprogram {
        /**
         * 0 数治健康
         */
        HEALTHY(0),
        /**
         * 1 数治工具箱
         */
        TOOLS(1);

        private int type;
    }


}
